#include "wms_button.h"

bool callwebportal = false;
bool iskeypressed = false;

OneButton button1(PIN_KEY, true);

void IRAM_ATTR key_callback()

{
  Serial.println("PAD_1_callback");
  iskeypressed = true;
}

void pad_1_singleClick()
{
  key_callback();
}
void pad_1_doubleClick()
{
}
void pad_1_multiClick()
{
  int i = button1.getNumberClicks();
  if (i == 4)
  {
    callwebportal = true;
  }
}
void pad_1_pressStop()
{
  Serial.print("pressStop()......call for esp reboot");
  ESP.restart();
}

IRAM_ATTR void checkTicks()
{
  button1.tick();
}

void button_init() {
  attachInterrupt(digitalPinToInterrupt(PIN_KEY), checkTicks, CHANGE);
  button1.attachClick(pad_1_singleClick);
  button1.attachDoubleClick(pad_1_doubleClick);
  button1.attachMultiClick(pad_1_multiClick);
  button1.attachLongPressStop(pad_1_pressStop);

  button1.setPressMs(3000); // that is the time when LongPressStart is called
} 
void btn_tick(){
  checkTicks();
}
